<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background: url(../img/1.jpg) no-repeat top center;
        }
    </style>
</head>

<body>
    ">
    <script>
        const random = Math.floor(Math.random() * 3) + 1
        // const body = document.querySelector('body') //因为只有一个body 所以不需要获取了
        document.body.style.backgroundImage = `url(../img/${random}.jpg)`

    </script>
</body>

</html>